<?php
defined('APP') or die('Do not have permission to access');

class Core_Router
{
    public static $controller;
    public static $action;

    public static function loader()
    {
        self::$controller = (empty($_GET["mod"])) ? Core::$config["loadDefault"][SECTION]["mod"] : $_GET["mod"];
        self::$action = (empty($_GET["task"])) ? Core::$config["loadDefault"][SECTION]["task"] : $_GET["task"];
        self::getController();
    }

    private static function getController()
    {
        $fileController = 'application' . DS . 'modules' . DS . SECTION . DS. 'controllers'. DS . ucwords(self::$controller) . 'Controller.php';
        if (!file_exists($fileController)) {
            die('Invalid view file : ' . $fileController);
        }
        require_once $fileController;
        $controllerName = self::$controller . 'Controller';
        $actionName = strtolower(self::$action);
        $controllerLoad = new $controllerName();
        $controllerLoad->$actionName();
    }
}